<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <link rel="stylesheet" href="eye.css">
</head>
<body>
  <div class="box">
    <label>
      <img src="images/close.png" id="eye">
    </label>
    <input type="password" id="pwd">
  </div>
  <script>
    // 获取元素
    var eye = document.getElementById('eye');
    var pwd = document.getElementById('pwd');
    // 注册事件
    eye.onclick = function () {
      if (pwd.type == 'password') {
        pwd.type = 'text';
        eye.src = 'images/open.png';
      } else {
        pwd.type = 'password';
        eye.src = 'images/close.png';
      }
    };
  </script>
</body>
<html>